﻿using AntdUI;
using PosClient.Delegates;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PosClient.Controls
{
    public partial class GoodRow : Control , INotifyPropertyChanged
    {
        public GoodRow()
        {
            InitializeComponent();
            InitEvent();
        }

        public event RowClickEventHandler RowClick;
        private void InitEvent()
        {
            Click += (s, e) =>
            {
                RowClick.Invoke(this,e);
            };

            stackPanel_base.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };

            avatar_img.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };

            label_title.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };

            label_price.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };
        }

        private string _Title;
        private string _Price;
        private int _Index;
        private object _TagData;
        private Color _Item_Back;
        private bool _Check;
        private string _Svg;
        private Image _Image;


        [Description("标题品名"), Category("外观"), DefaultValue(false)]
        public string Title
        {
            get => _Title;
            set
            {
                if (_Title == value) return;
                _Title = value;
                label_title.Text = _Title;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("价格"), Category("外观"), DefaultValue(false)]
        public string Price
        {
            get => _Price;
            set
            {
                if (_Price == value) return;
                _Price = value;
                label_price.Text = _Price;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("Svg图片"), Category("外观"), DefaultValue(false)]
        public string Svg
        {
            get => _Svg;
            set
            {
                if (_Svg == value) return;
                _Svg = value;
                avatar_img.ImageSvg = _Svg;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("Svg图片"), Category("外观"), DefaultValue(false)]
        public Image Image
        {
            get => _Image;
            set
            {
                if (_Image == value) return;
                _Image = value;
                avatar_img.Image = _Image;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("索引"), Category("外观"), DefaultValue(-1)]
        public int Index
        {
            get => _Index;
            set
            {
                if (_Index == value) return;
                _Index = value;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("自定义数据"), Category("外观"), DefaultValue(null)]
        public object TagData
        {
            get => _TagData;
            set
            {
                if (_TagData == value) return;
                _TagData = value;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("背景色"), Category("外观"), DefaultValue(null)]
        public Color Item_Back
        {
            get => _Item_Back;
            set
            {
                if (_Item_Back == value) return;
                _Item_Back = value;
                stackPanel_base.BackColor = _Item_Back;
                Invalidate();
            }
        }

        [Description("选中"), Category("外观"), DefaultValue(false)]
        public bool Check
        {
            get => _Check;
            set
            {
                if (_Check == value) return;
                _Check = value;
                stackPanel_base.BackColor = _Check ? Color.FromArgb(224, 228, 229) : Color.White;
                Invalidate();
                NotifyPropertyChanged();
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); //实现通知刷新
        }
    }
}
